package com.coolbi.common.util;

public class MatcheUtil {
	/** Email正则表达式 */
	public static final String REGEX_EMAIL = "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
	/** URL正则表达式 */
	public static final String REGEX_URL = "(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])?";
	/** 手机号正则表达式 */
	public static final String REGEX_TELEPHONE="^(1(([35][0-9])|(47)|[8][0126789]))\\d{8}$";
	
	/**
	 * 手机号正则表达式匹配
	 * @param telephone
	 * @return
	 */
	public static boolean matchTelephone(String telephone){
		return telephone.matches(REGEX_TELEPHONE);
	}
	
	/**
	 * Email正则表达式匹配
	 * @param email
	 * @return
	 */
	public static boolean matcheEmail(String email) {
		return email.matches(REGEX_EMAIL);
	}

	/**
	 * URL正则表达试匹配
	 * @param url
	 * @return
	 */
	public static boolean matcheUrl(String url) {
		return url.matches(REGEX_URL);
	}
	
	/**
	 * 匹配指定长度的数字
	 * @param target
	 * @param length
	 * @return
	 */
	public static boolean matcheReg(String target,int length){
		return target.matches("^\\d{"+length+"}$");
	}
}
